package com.bzxgc.sgwer.service.impl.project;

import com.bzxgc.sgwer.common.util.PageData;
import com.bzxgc.sgwer.dao.project.ProjectMapper;
import com.bzxgc.sgwer.entity.project.Project;
import com.bzxgc.sgwer.service.project.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ProjectServiceImpl implements ProjectService {

    @Autowired
    private ProjectMapper projectMapper;

    @Override
    public Project getProjectByName(String name) {
        return projectMapper.getProjectByName(name);
    }

    @Override
    public PageData<Project> getProjectListByPage(Integer pageNum, Integer pageSize, String name) {
        List<Project> projectList = projectMapper.getProjectListByPage(PageData.fromIndex(pageNum, pageSize), pageSize, name);
        Integer totalRecord = projectMapper.getProjectCount(name);
        PageData<Project> pageData = new PageData<>(pageSize, pageNum, totalRecord, projectList);
        return pageData;
    }

    @Override
    public Integer getProjectCount(String name) {
        return projectMapper.getProjectCount(name);
    }

    @Override
    public List<Project> getAllProject() {
        return projectMapper.getAllProject();
    }

    @Override
    public Project getProjectById(Long id) {
        return projectMapper.getProjectById(id);
    }

    @Override
    public void addProject(Project project) {
        project.setAddTime(new Date());
        project.setStatus(1);
        projectMapper.addProject(project);
    }

    @Override
    public void updateProject(Project project) {
        project.setUpdateTime(new Date());
        projectMapper.updateProject(project);
    }

    @Override
    public void updateProjectStatus(Long[] ids, Integer status) {
        projectMapper.updateProjectStatus(ids, status);
    }
}
